/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
   this file is part of rcssserver3D
   Fri May 9 2003
   Copyright (C) 2003 Koblenz University
   $Id$

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
// -*- C++ -*- generated by wxGlade 0.4 on Sat Jan 21 16:34:57 2006

#include "propertyframe.h"
#include "main.h"
#include "simspark.h"

//! wxWidgets and zeitgeist both use a 'DECLARE_CLASS' macro
#undef DECLARE_CLASS

#include <oxygen/sceneserver/basenode.h>

using namespace boost;
using namespace zeitgeist;

propertyframe::propertyframe(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long /*style*/):
    wxFrame(parent, id, title, pos, size, wxCAPTION|wxCLOSE_BOX|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxSYSTEM_MENU|wxRESIZE_BORDER|wxFRAME_TOOL_WINDOW|wxFRAME_FLOAT_ON_PARENT|wxCLIP_CHILDREN)
{
    // begin wxGlade: propertyframe::propertyframe
    mCtrPropList = new wxListCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxSUNKEN_BORDER);

    set_properties();
    do_layout();
    // end wxGlade
}


void propertyframe::set_properties()
{
    // begin wxGlade: propertyframe::set_properties
    SetTitle(wxT("frame_1"));
    SetSize(wxSize(400, 150));
    // end wxGlade
}


void propertyframe::do_layout()
{
    // begin wxGlade: propertyframe::do_layout
    wxBoxSizer* sizer_3 = new wxBoxSizer(wxVERTICAL);
    sizer_3->Add(mCtrPropList, 1, wxEXPAND, 0);
    SetSizer(sizer_3);
    Layout();
    // end wxGlade
}

void propertyframe::UpdateCached()
{
    shared_ptr<SimSpark> spark = wxGetApp().GetSpark();
    if (spark.get() == 0)
        {
            return;
        }

    mPath.Update(spark->GetCore());
    mPropList.Init(mPath.get(),mCtrPropList);
}

void propertyframe::SetLeaf(weak_ptr<Leaf> leaf)
{
    shared_ptr<SimSpark> spark = wxGetApp().GetSpark();
    if (spark.get() == 0)
        {
            return;
        }

    if (leaf.expired())
    {
        mPath = Leaf::CachedPath<zeitgeist::Leaf>();
    } else
    {
        std::string path = leaf.lock()->GetFullPath();
        mPath.SetKey(Core::CacheKey(spark->GetCore()->GetRoot(), path));
    }

    UpdateCached();
    RefreshProperties();
}

void propertyframe::RefreshProperties()
{
    mPropList.Refresh();
}
